#ifndef __CRIBLEMPI_HPP__
#define __CRIBLEMPI_HPP__

#include "gmpxx.h"
#include "Factor.hpp"
#include "Paire.hpp"
#include "Polynome.hpp"

class CribleMPI
{
   
   protected :
      
      Factor * _rationnalFactorBase;
      
      Factor * _algebraicFactorBase;
      
      mpz_class _n;
      
      mpz_class _m;
            
   public :
      
      CribleMPI(Factor * inRationnalFactorBase, Factor * inAlgebraicFactorBase, mpz_class inN, mpz_class inM)
      {
         
         _rationnalFactorBase = inRationnalFactorBase;
         
         _algebraicFactorBase = inAlgebraicFactorBase;
         _n = inN;
         _m = inM;
      }
      
      ~CribleMPI() {}
      
      Factor * sieving(mpz_class inLowBound, mpz_class inUpBound, int inNbelementRationnal, Erathostene & erathostene, Polynome & poly, int inNbB) const;
      
      inline mpz_class * placementTableau(mpz_class * inTab, mpz_class inNbElement, mpz_class inIndice, mpz_class inNombre) const
      {
         mpz_class * ptrTab = inTab;
         mpz_class   value = (inNbElement -1) / 2;  // 0
         mpz_class   cpt = 0;
         

         for( ; cmp(cpt, value + inIndice) < 0 ; cpt += 1)
         {
            ptrTab++;
         }
         
         *ptrTab *= inNombre;
         
         return inTab;
      }
      
      
      
   private :
      
      Factor * Master(int inNbMaxCouple, int inNbB) const;
      
      void Slave(mpz_class inLowBound, mpz_class inUpBound, int inNbelementRationnal, Erathostene & erathostene, Polynome & poly, int inNbMaxCouple) const;

};

#endif
